﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using TuringVM.Core;

namespace TuringVM.Esoteric.Preprocessors
{
    public class BrainfuckPreprocessor: PreprocessorBase
    {
        private CommandSet _commands = Esoteric.GetDefaultCommandSet();
        private HashSet<char> _chars = new HashSet<char>("><+-.,[]".ToCharArray());

        public override string Process(string source)
        {
            StringBuilder result = new StringBuilder();
            foreach (char token in source)
            {
                if (_chars.Contains(token))
                {
                    switch (token)
                    {
                        case '>':
                            result.AppendLine("MoveRight");
                            break;
                        case '<':
                            result.AppendLine("MoveLeft");
                            break;
                        case '+':
                            result.AppendLine("Inc");
                            break;
                        case '-':
                            result.AppendLine("Dec");
                            break;
                        case '.':
                            result.AppendLine("Write");
                            break;
                        case ',':
                            result.AppendLine("Read");
                            break;
                        case '[':
                            result.AppendLine("LoopBegin");
                            break;
                        case ']':
                            result.AppendLine("LoopEnd");
                            break;
                    }
                }
            }
            return result.ToString();
        }
    }
}
